﻿using System;
using System.Collections.Generic;
using System.Text;
using XDesigner.ORM;
using System.ComponentModel;

namespace XDesigner.AppFramework.DOM
{
    [Serializable()]
    public class AppCategoryList : System.Collections.CollectionBase
    {
        public AppCategory this[int index]
        {
            get
            {
                return (AppCategory)this.List[index];
            }
        }
        public AppCategory this[string name]
        {
            get
            {
                foreach (AppCategory item in this)
                {
                    if (string.Equals(item.CategoryName, name, StringComparison.CurrentCultureIgnoreCase))
                    {
                        return item;
                    }
                }
                return null;
            }
        }

        public int Add(AppCategory item)
        {
            return this.List.Add(item);
        }

        public void Remove(AppCategory item)
        {
            this.List.Remove(item);
        }
         
    }

    [Serializable()]
    [ORMType("Table_AppCategory", Buffered = ORMBooleanValue.True)]
    public class AppCategory
    {
        public AppCategory()
        {
        }

        private int _RecordID = -1;
        [ORMKeyField()]
        public virtual int RecordID
        {
            get
            {
                return _RecordID; 
            }
            set
            {
                _RecordID = value; 
            }
        }


        private string _GategoryName = null;
        [DefaultValue( null)]
        [ORMSort( ORMSortStyle.Ascent )]
        public virtual string CategoryName
        {
            get
            {
                return _GategoryName; 
            }
            set
            {
                _GategoryName = value; 
            }
        }

        private string _Description = null;
        [DefaultValue( null)]
        public virtual string Description
        {
            get
            {
                return _Description; 
            }
            set
            {
                _Description = value; 
            }
        }


        private bool _Enabled = true;
        [DefaultValue(true)]
        public virtual bool Enabled
        {
            get
            {
                return _Enabled;
            }
            set
            {
                _Enabled = value;
            }
        }

        private List<AppCategoryValue> _Values = null;
        [ORMRelation( ORMRelationStyle.OneToMany ,UniteDeleteForDelete=true)]
        [ORMDelay()]
        [DefaultValue(null)]
        public virtual List<AppCategoryValue> Values
        {
            get
            {
                return _Values; 
            }
            set
            {
                _Values = value; 
            }
        }

        public void FillValueNames(System.Collections.IList list)
        {
            if (list != null)
            {
                if (this.Values != null)
                {
                    foreach (AppCategoryValue v in this.Values)
                    {
                        if (v.ItemName != null)
                        {
                            list.Add(v.ItemName);
                        }
                    }//foreach
                }//if
            }//if
        }

        [System.ComponentModel.Browsable( false )]
        public string DisplayName
        {
            get
            {
                string text = this.RecordID.ToString();
                text = text + new string(' ', 8 - text.Length);
                return text + this.CategoryName;
            }
        }
    }

    [Serializable()]
    [ORMType("Table_AppCategoryValue", Buffered = ORMBooleanValue.True )]
    public class AppCategoryValue
    {
        public AppCategoryValue()
        {
        }


        private int _RecordID = -1;
        [ORMKeyField()]
        public virtual int RecordID
        {
            get
            {
                return _RecordID; 
            }
            set
            {
                _RecordID = value; 
            }
        }

        private AppCategory _OwnerCategory = null;
        [ORMRelation( ORMRelationStyle.OneToOne )]
        [ORMParentReference()]
        [ORMField("CategoryID")]
        [System.ComponentModel.Browsable( false )]
        [System.Xml.Serialization.XmlIgnore()]
        public virtual AppCategory OwnerCategory
        {
            get
            {
                return _OwnerCategory; 
            }
            set
            {
                _OwnerCategory = value; 
            }
        }

        private string _ItemName = null;
        [DefaultValue(null)]
        [ORMSort( ORMSortStyle.Ascent )]
        public virtual string ItemName
        {
            get { return _ItemName; }
            set { _ItemName = value; }
        }

        private string _ItemValue = null;
        [DefaultValue(null)]
        public virtual string ItemValue
        {
            get { return _ItemValue; }
            set { _ItemValue = value; }
        }

        private string _Description = null;
        [DefaultValue(null)]
        public virtual string Description
        {
            get { return _Description; }
            set { _Description = value; }
        }
         
        private bool _Enabled = true;
        [DefaultValue(true)]
        public virtual bool Enabled
        {
            get { return _Enabled; }
            set { _Enabled = value; }
        }

    }
}
